home *** CD-ROM | disk | FTP | other *** search
- <?php
- /*
- ** $Id: index.php,v 1.14 2005/07/14 10:35:55 hmailserver Exp $
- **
- ** hMailServer - Web interface
- **
- ** File formatted using TAB size 4
- **
- ** Get hMailserver at http://www.hmailserver.com
- **
- ** Author: Steen Rab°l <srabol@mail.tele.dk>
- ** Copyright (c) 2004, Steen Rab°l <srabol@mail.tele.dk>
- **
- ** This program is free software; you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation; either version 2 of the License, or
- ** (at your option) any later version.
- **
- ** You may not change or alter any portion of this comment or credits
- ** of supporting developers from this source code or any supporting
- ** source code which is considered copyrighted (c) material of the
- ** original comment or credit authors.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program; if not, write to the Free Software
- ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- **
- */
-
- if (!file_exists("config.php"))
- {
- echo "Please rename config-dist.php to config.php. The file is found in the PHPWebAdmin root folder.";
- die;
- }
-
- require_once("config.php");
- require_once("mhwainit.php");
-
- $loggedin = hmailGetVar("loggedin",0);
- $hmailSmarty->assign("loggedin",$loggedin);
- $page = hmailGetVar("page","frontpage");
- if ($loggedin != 1)
- {
- $page = "login";
- $page = $page . ".php";
- $maintemplate = "login.tpl";
- require_once($page);
- }
- else
- {
- $page = $page . ".php";
- require_once($page);
- $maintemplate = "index.tpl";
-
- // Build tree menu
- $obSettings = $obBaseApp->Settings();
- $obDomains = $obBaseApp->Domains();
-
- $DomainCount = $obDomains->Count();
- $dtitem=0;
-
- $dtree = "d.add(" . $dtitem++ .",-1,'" . hmailGetLocaleText("welcome") . "','index.php','" . hmailGetLocaleText("welcome") ."');\r\n";
-
- if (hmailGetAdminLevel() == 0)
- {
- // User
- $domainname = hmailGetUserDomainName($_SESSION['username']);
-
- $obDomain = $obBaseApp->Domains->ItemByName($domainname);
- $obAccounts = $obDomain->Accounts;
- $obAccount = $obAccounts->ItemByAddress($_SESSION['username']);
-
- $url = htmlentities("index.php?page=accounts_edit&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID);
- $di = $dtitem++;
- $dtree .= "d.add($di,0,'" . $obAccount->Address . "','$url','','','" . $hmail_config['themepath'] . "images/user.gif','" . $hmail_config['themepath'] . "images/user.gif');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",$di,'" . hmailGetLocaleText("auto_reply") . "','index.php?page=accounts_autoreply&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
- }
-
-
- if (hmailGetAdminLevel() == 1)
- {
- // Domain
-
- $dtree .= "d.add(" . $dtitem++ .",0,'" . hmailGetLocaleText("domains") . "','','','','" . $hmail_config['themepath'] . "images/s_host.png','" . $hmail_config['themepath'] . "images/s_host.png');\r\n";
-
- $domainname = hmailGetUserDomainName($_SESSION['username']);
-
- $obDomain = $obBaseApp->Domains->ItemByName($domainname);
- $domain_root = $dtitem++;
-
- GetStringForDomain($obDomain);
- }
-
- if (hmailGetAdminLevel() == 2)
- {
- // Server
-
- $dtree .= "d.add(" . $dtitem++ .",0,'" . hmailGetLocaleText("domains") . " ($DomainCount)','index.php?page=domains','','','" . $hmail_config['themepath'] . "images/s_host.png','" . $hmail_config['themepath'] . "images/s_host.png');\r\n";
-
- for ($i = 1; $i <= $DomainCount; $i++)
- {
- $obDomain = $obBaseApp->Domains[$i-1];
- $domain_root = $dtitem++;
-
- GetStringForDomain($obDomain);
- }
-
-
- $dtree .= "d.add(" . $dtitem++ . ",0,'" . hmailGetLocaleText("server") . "','index.php?page=services','','','" . $hmail_config['themepath'] ."images/globe.gif');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",0,'" . hmailGetLocaleText("mx_query") . "','index.php?page=mxquery');\r\n";
- $settings_root = $dtitem++;
- $dtree .= "d.add(" . $settings_root . ",0,'" . hmailGetLocaleText("settings") . "','index.php?page=settings','','','" . $hmail_config['themepath'] . "images/settings.gif','" . $hmail_config['themepath'] . "images/settings.gif');\r\n";
- $settings_smtp_root = $dtitem++;
- $dtree .= "d.add(" . $settings_smtp_root . ",$settings_root,'" . hmailGetLocaleText("smtp") . "','index.php?page=settings_smtp');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",$settings_smtp_root,'" . hmailGetLocaleText("security") . "','index.php?page=settings_smtp_security');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",$settings_smtp_root,'" . hmailGetLocaleText("antivirus") . "','index.php?page=settings_smtp_antivirus');\r\n";
- $settings_smtp_route = $dtitem++;
-
- $obRoutes = $obSettings->Routes();
- $Count = $obRoutes->Count();
- $dtree .= "d.add(" . $settings_smtp_route . ",$settings_smtp_root,'" . hmailGetLocaleText("routes") . " (" . $Count . ")','index.php?page=settings_smtp_routes');\r\n";
-
- for ($i = 0; $i < $Count; $i++)
- {
- $obRoute = $obRoutes->Item($i);
- $di = $dtitem++;
- $dtree .= "d.add($di,$settings_smtp_route,'" . $obRoute->DomainName . "','index.php?page=settings_smtp_routes_edit&RouteID=" . $obRoute->ID . "');\r\n";
- $dsub = $dtitem++;
- $dtree .= "d.add($dsub,$di,'" . hmailGetLocaleText("addresses") . "','index.php?page=settings_smtp_routes_addresses&RouteID=" . $obRoute->ID . "');\r\n";
- $dsub = $dtitem++;
- $dtree .= "d.add($dsub,$di,'" . hmailGetLocaleText("delivery") . "','index.php?page=settings_smtp_routes_delivery&RouteID=" . $obRoute->ID . "');\r\n";
- }
-
- $dtree .= "d.add(" . $dtitem++ . ",$settings_root,'" . hmailGetLocaleText("pop3") . "','index.php?page=settings_pop3');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",$settings_root,'" . hmailGetLocaleText("imap") . "','index.php?page=settings_imap');\r\n";
-
- $obSecurityRanges = $obSettings->SecurityRanges();
- $obSecurityRanges->Refresh();
- $Count = $obSecurityRanges->Count();
-
- $settings_ipranges_root = $dtitem++;
- $dtree .= "d.add(" . $settings_ipranges_root . ",$settings_root,'" . hmailGetLocaleText("ip_ranges") . " ($Count)','index.php?page=settings_ipranges');\r\n";
-
- for ($j = 0; $j < $Count; $j++)
- {
- $obSecurityRange = $obSecurityRanges->Item($j);
- $di = $dtitem++;
- $dtree .= "d.add($di,$settings_ipranges_root,'" . $obSecurityRange->Name . "','index.php?page=settings_ipranges_edit&IPRangeID=" . $obSecurityRange->ID . "');\r\n";
- }
- $dtree .= "d.add(" . $dtitem++ . ",$settings_root,'" . hmailGetLocaleText("logging") . "','index.php?page=settings_logging');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",$settings_root,'" . hmailGetLocaleText("mirror") . "','index.php?page=settings_mirror');\r\n";
- $tools_root = $dtitem++;
- $dtree .= "d.add(" . $tools_root . ",0,'" . hmailGetLocaleText("tools") . "','index.php?page=tools','','','" . $hmail_config['themepath'] . "images/tools.png','" . $hmail_config['themepath'] . "images/tools.png');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",$tools_root,'" . hmailGetLocaleText("backup") . "','index.php?page=tools_backup');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",$tools_root,'" . hmailGetLocaleText("restore") . "','index.php?page=tools_restore');\r\n";
-
- // Plugins
- // Scan the plugin dir for files
- $plugins = getFilesInDir($hmail_config['pluginpath']);
-
- if(is_array($plugins) && count($plugins) >0)
- {
- $plugins_root = $dtitem++;
- $dtree .= "d.add(" . $plugins_root . ",0,'" . hmailGetLocaleText("plugins") . "','','','','" . $hmail_config['themepath'] . "images/tools.png','" . $hmail_config['themepath'] . "images/tools.png');\r\n";
-
- // read plugins
- foreach($plugins as $plugin)
- {
- $menufunc = basename($plugin,".php") . "_menu";
- $pluginname = str_replace("plugin_","",basename($plugin,".php"));
- $includefile = $hmail_config['pluginpath'] . $plugin;
- include_once($includefile);
- $menuname = $menufunc();
- $dtree .= "d.add(" . $dtitem++ . ",$plugins_root,'" . $menuname . "','index.php?page=plugin&plugin=$pluginname','','','" . $hmail_config['themepath'] . "images/tools.png','" . $hmail_config['themepath'] . "images/tools.png');\r\n";
- }
- }
- }
-
- $dtree .= "d.add(" . $dtitem++ .",-1,'" . hmailGetLocaleText("logout") . "','logout.php','" . hmailGetLocaleText("logout") ."');\r\n";
-
- $dtree .= "document.write(d);";
- $hmailSmarty->assign("dtree",$dtree);
- }
-
- function GetStringForDomain($obDomain)
- {
- // I know this is ugly... / Martin
- global $dtree, $domain, $dtitem, $domain_root, $hmail_config;
-
- $dtree .= "d.add($domain_root,1,'" . $obDomain->Name . "','index.php?page=domain_edit&DomainID=" . $obDomain->ID . "','','','" . $hmail_config['themepath'] . "images/b_home.png','" . $hmail_config['themepath'] . "images/b_home.png');\r\n";
-
- $obAccounts = $obDomain->Accounts();
- $AccountsCount = $obAccounts->Count();
- $accounts_root = $dtitem++;
- $dtree .= "d.add($accounts_root,$domain_root,'" . hmailGetLocaleText("accounts") . " ($AccountsCount)','index.php?page=accounts&DomainID=" . $obDomain->ID . "','','','" . $hmail_config['themepath'] . "images/b_usrlist.png','" . $hmail_config['themepath'] . "images/b_usrlist.png');\r\n";
- for ($j = 0; $j < $AccountsCount; $j++)
- {
- $obAccount = $obAccounts->Item($j);
- $di = $dtitem++;
- $url = htmlentities("index.php?page=accounts_edit&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID);
- $dtree .= "d.add($di,$accounts_root,'" . $obAccount->Address . "','$url','','','" . $hmail_config['themepath'] . "images/user.gif','" . $hmail_config['themepath'] . "images/user.gif');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",$di,'" . hmailGetLocaleText("auto_reply") . "','index.php?page=accounts_autoreply&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
- $dtree .= "d.add(" . $dtitem++ . ",$di,'" . hmailGetLocaleText("active_directory") . "','index.php?page=accounts_activedirectory&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
- }
-
- $obAliases = $obDomain->Aliases();
- $AliasesCount = $obAliases->Count();
- $aliases_root = $dtitem++;
- $dtree .= "d.add($aliases_root,$domain_root,'" . hmailGetLocaleText("aliases") . " ($AliasesCount)','index.php?page=alias&DomainID=" . $obDomain->ID . "');\r\n";
-
- for ($j = 0; $j < $AliasesCount; $j++)
- {
- $obAlias = $obAliases->Item($j);
- $di = $dtitem++;
- $dtree .= "d.add($di,$aliases_root,'" . $obAlias->Name . "','index.php?page=alias_edit&AliasID=" . $obAlias->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
- }
-
- $obDistributionLists = $obDomain->DistributionLists();
- $DListCount = $obDistributionLists->Count();
- $dlist_root = $dtitem++;
- $dtree .= "d.add($dlist_root,$domain_root,'" . hmailGetLocaleText("distribution_lists") . " ($DListCount)','index.php?page=distributionlists&DomainID=" . $obDomain->ID . "');\r\n";
-
- for ($j = 0; $j < $DListCount; $j++)
- {
- $obDistributionList = $obDistributionLists->Item($j);
- $di = $dtitem++;
- $dtree .= "d.add($di,$dlist_root,'" . $obDistributionList->Address . "','index.php?page=distributionlists_edit&DistributionlistID=" . $obDistributionList->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
- $dtree .= "d.add(" . $dtitem++ .",$di,'" . hmailGetLocaleText("recipients") . " (" . $obDistributionList->Recipients->Count() . ")','index.php?page=distributionlists_recipients&DistributionlistID=" . $obDistributionList->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
- }
-
-
- }
-
- function getFilesInDir($p_path)
- {
- $files = array();
- if(is_readable($p_path))
- {
- // Open current directory
- if($handle = opendir($p_path))
- {
- // Loop through all files
- while(false !== ($file = readdir($handle)))
- {
- // Ignore hidden files
- if(!preg_match("/^\./", $file))
- {
- // Put dirs in $dirs[] and files in $files[]
- if(!is_dir($file))
- {
- $files[] = $file;
- }
- }
- }
-
- // Close directory
- closedir($handle);
- // if $files[] exists, sort it and print all elements in it.
- if(is_array($files))
- {
- sort($files);
- }
- }
- }
-
- return $files;
- }
- $hmailSmarty->display($maintemplate);
-
- ?>
-